package com.huang.viewpage;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.clovsoft.banner.BannerTabLayout;
import com.clovsoft.banner.ViewPagerAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager2 viewPager2;
    private BannerTabLayout tabLayout;
    private List<Fragment> fragmentList = new ArrayList<>();
    private ViewPagerAdapter adapter;

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager2 = findViewById(R.id.view_pager);
        tabLayout = findViewById(R.id.tab_layout);
        initFragment();
        adapter = new ViewPagerAdapter(this.getSupportFragmentManager(), getLifecycle(), fragmentList);
        viewPager2.setAdapter(adapter);
        tabLayout.setDotAndSwitchColor(this, viewPager2);
        tabLayout.setTabMinWidth(15, 30,30);
//        tabLayout.setSelectedTabIndicatorFixWidth(1000);

//        tabLayout.setDotAndSwitchColor(this, viewPager2,R.color.black,R.color.white);
    }

    private void initFragment() {
        fragmentList.add(new FirstFragment());
        fragmentList.add(new SecondFragment());
        fragmentList.add(new ThirdFragment());
    }

}